<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/24
 * Time: 17:20
 */
namespace app\api\controller\v1;

use app\api\validate\IDMustPositveInt;
use app\api\validate\IDConllection;
use app\lib\exception\ThemeException;
use think\Controller;
use app\api\model\Theme as ThemeModel;

class Theme extends Controller{

    /**
     * @url /theme?ids=1,2,3
     * 获取所有专题信息
     * @param string $ids
     *
     * @return \think\response\Json
     * @throws ThemeException
     * @throws \app\lib\exception\ParemeterException
     */
    public function getSimpleList($ids = ''){
        (new IDConllection())->goCheck();
        $theme = ThemeModel::getThemeByIDs($ids);
        if(!$theme){
            throw new ThemeException();
        }
        return json(['code'=>200,'msg'=>'OK','data'=>$theme]);
    }

    /**
     * 获取指定主题的详情信息
     * @param $id
     *
     * @return \think\response\Json
     * @throws ThemeException
     * @throws \app\lib\exception\ParemeterException
     */
    public function getComplexOne($id){
        (new IDMustPositveInt())->goCheck();
        $theme = ThemeModel::getThemeWithProducts($id);
        if(!$theme){
            throw new ThemeException();
        }
        return json(['code'=>200,'msg'=>'OK','data'=>$theme]);
    }
}